import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class MongoInsert {
    public static void main(String[] args) {
        MongoClient mongoClient = new MongoClient("192.168.221.135");
        MongoDatabase spitdb = mongoClient.getDatabase("spitdb");
        MongoCollection<Document> spit = spitdb.getCollection("spit");
        Map<String, Object> map = new HashMap<>();
        map.put("content","我要吐槽");
        map.put("userid","9999");
        map.put("visits",123);
        map.put("publishtime",new Date());
        Document document = new Document(map);
        spit.insertOne(document);
        mongoClient.close();
    }
}
